<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
</head>
<style>
    html,
    body {
        background-color: #fbf9f9;
    }

    .item {
        padding: 1rem 3%;
        width: 94%;
        background-color: #fff;
        border-bottom: 1px solid #ccc;
        color: #000;
    }

    .item:last-child {
        border: none;
    }

    .item .title {
        color: #888;
        font-size: 0.8rem;
    }

    .item .status {
        font-size: 0.8rem;
        margin: 1rem 0;
    }

    .item .status img {
        float: right;
        width: 2rem;
        height: 1rem;
    }

    .item .price {
        font-size: 0.8rem;
    }

    .item .price .right {
        float: right;
        font-size: 0.9rem;
    }

    .item .price .right img {
        width: 0.4rem;
        height: 0.8rem;
        margin-left: 0.5rem;
        margin-top: -0.15rem;
    }
</style>

<body>
    <div id="app" v-cloak>
        <div class="item">
            <p class="title">图文问诊</p>
            <div class="status" @click="tuwen = !tuwen,edit(1,tuwen,tuwen_price)">
                开通状态
                <img :src="tuwen ? '../image/checkbox_true.png' : '../image/checkbox_false.png'" alt="">
            </div>
            <div class="price" @click="go_my_medical_service_price_win(1,tuwen_price)">
                图文问诊价格
                <div class="right">
                    <span>￥{{tuwen_price}}</span>
                    <img src="../image/arrow_right.png" alt="">
                </div>
            </div>
        </div>
        <div class="item">
            <p class="title">语音问诊</p>
            <div class="status" @click="yuyin = !yuyin,edit(2,yuyin,yuyin_price)">
                开通状态
                <img :src="yuyin ? '../image/checkbox_true.png' : '../image/checkbox_false.png'" alt="">
            </div>
            <div class="price" @click="go_my_medical_service_price_win(2,yuyin_price)">
                语音问诊价格
                <div class="right">
                    <span>￥{{yuyin_price}}</span>
                    <img src="../image/arrow_right.png" alt="">
                </div>
            </div>
        </div>
        <div class="item">
            <p class="title">视频问诊</p>
            <div class="status" @click="shipin = !shipin,edit(3,shipin,shipin_price)">
                开通状态
                <img :src="shipin ? '../image/checkbox_true.png' : '../image/checkbox_false.png'" alt="">
            </div>
            <div class="price" @click="go_my_medical_service_price_win(3,shipin_price)">
                视频问诊价格
                <div class="right">
                    <span>￥{{shipin_price}}</span>
                    <img src="../image/arrow_right.png" alt="">
                </div>
            </div>
        </div>
    </div>
</body>

</html>
<script src="../script/set_root.js"></script>

<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/zepto.min.js"></script>
<script type="text/javascript" src="../script/hb.js"></script>
<script type="text/javascript" src="../script/vue.js"></script>
<script type="text/javascript">
    apiready = function () {
        hb_ready();

        getData()

        api.addEventListener({
            name: 'editService'
        }, function (ret, err) {
            getData()
        });
    }
    //使用vue对数据进行绑定
    var app = new Vue({
        el: '#app',
        data: {
            tuwen: false,
            tuwen_price: 0,
            yuyin: false,
            yuyin_price: 0,
            shipin: false,
            shipin_price: 0,
            serviceList: [],
        },
        methods: {
            go_my_medical_service_price_win(index, price) {
                api.openWin({
                    name: "my_medical_service_price_win",
                    url: "my_medical_service_price_win.html",
                    pageParam: {
                        index: index,
                        id: price
                    }
                })
            },
            edit(index, val, price) {
                var vals = ""
                if (val) {
                    vals = 1
                } else {
                    vals = 0
                }
                if (index == 1) {
                    post_ajax("doctor/services/save", {
                        doctorId: $api.getStorage("emp").userId,
                        name: "image",
                        title: "图文",
                        group: "consultation",
                        values: {
                            price: price,
                            enable: vals
                        }
                    }, function (res, err) {
                        if (res.code == 2000) {
                            toast("修改成功")
                            getData()
                        } else {
                            alert(JSON.stringify(res.msg))
                        }
                    })
                } else if (index == 2) {
                    post_ajax("doctor/services/save", {
                        doctorId: $api.getStorage("emp").userId,
                        name: "audio",
                        title: "语音",
                        group: "consultation",
                        values: {
                            price: price,
                            enable: vals
                        }
                    }, function (res, err) {
                        if (res.code == 2000) {
                            toast("修改成功")
                            getData()
                        } else {
                            alert(JSON.stringify(res.msg))
                        }
                    })
                } else if (index == 3) {
                    post_ajax("doctor/services/save", {
                        doctorId: $api.getStorage("emp").userId,
                        name: "video",
                        title: "视频",
                        group: "consultation",
                        values: {
                            price: price,
                            enable: vals
                        }
                    }, function (res, err) {
                        if (res.code == 2000) {
                            toast("修改成功")
                            getData()
                        } else {
                            alert(JSON.stringify(res.msg))
                        }
                    })
                }
            }
        }
    })

    function getData() {
        get_ajax("doctor/services/list", {
            doctorId: $api.getStorage("emp").userId
        }, function (res, err) {
            if (res.data) {
                app.serviceList = res.data
                for (var i = 0; i < res.data.length; i++) {
                    if (res.data[i].name == "image") {
                        if (res.data[i].values.enable == 1) {
                            app.tuwen = true
                        } else {
                            app.tuwen = false
                        }
                        app.tuwen_price = res.data[i].values.price
                    } else if (res.data[i].name == "audio") {
                        if (res.data[i].values.enable == 1) {
                            app.yuyin = true
                        } else {
                            app.yuyin = false
                        }
                        app.yuyin_price = res.data[i].values.price
                    } else if (res.data[i].name == "video") {
                        if (res.data[i].values.enable == 1) {
                            app.shipin = true
                        } else {
                            app.shipin = false
                        }
                        app.shipin_price = res.data[i].values.price
                    }
                }
            }
        })
        app.$nextTick(function () {
            hb_init_openwinby_click();
        })
    }
</script>
